Spain’s Battle with COVID-19

rm(list=ls())
source("../DATA/movavg.R")
db <- db <- dbConnect(RSQLite::SQLite(),dbname= "../COVIDDB/COVID.sqlite3")
df <- dbGetQuery(db,"select * from ECDC")
df <- subset(df,Countries =="Spain"  )
df$Reported <- as.Date(df$Reported)
mean(df$Cases)
## [1] 4958.668
mean(df$Deaths)
## [1] 136.4585
US <- subset(df,Reported >="2020-04-01" & Cases >=1)
US <- US[order(US$Reported,decreasing = TRUE),]
US$MA14 <- movingAverage(US$Cases,14)
US$MAD <- movingAverage(US$Deaths,14)
US$Rate <- US$Deaths/US$Cases

Spain COVID19 Mortality Rate

A <- subset(US,Reported >="2020-07-01")
ggplot(A) + # geom_line(aes(x=Reported,y=Rate)) +
  scale_y_continuous(labels = scales::percent) +
  labs(title="Spain COVID19 Mortality Rate ",x="Date Reported",y="Mortality Rate") +
  geom_hline(yintercept = mean(A$Rate),col="red") +
  geom_smooth(aes(x=Reported,y=Rate,col="Loess"),span=0.15) +
  scale_alpha_date()
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'

Plot of Daily Cases and Deaths

daily_cases <-ggplot(US) +  # geom_line(aes(x=Reported,y=Cases,col="Daily Cases")) +
  labs(title="COVID-19 Cases by Date") +
    geom_smooth(aes(x=Reported,y=Cases,col="Loess"),span=0.15) +
   scale_alpha_date()

daily_deaths <-ggplot(US) + # geom_line(aes(x=Reported,y=Deaths,col="Daily Deaths")) +
  labs(title="COVID-19 Deaths by Date") + ylim(0,1000) +
  geom_smooth(aes(x=Reported,y=Deaths,col="Loess"), span=0.15) +
   scale_alpha_date()
  

ggplotly(daily_cases)
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
ggplotly(daily_deaths)
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
## Warning: Removed 3 rows containing non-finite values (stat_smooth).
USA <- subset(US,Reported >="2020-06-01")
ggplot(USA) + # geom_line(aes(x=Reported,y=Cases,col="Daily Cases")) +
  labs(title="COVID-19 Cases by Date since Jun. 1, 2020") +
  geom_smooth(aes(x=Reported,y=Cases,col="Loess"),span=0.25) +
   scale_alpha_date()
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'

ggplot(USA) + # geom_line(aes(x=Reported,y=Deaths,col="Daily Deaths")) +
  labs(title="COVID-19 Deaths by Date (since Jun. 1, 2020)") + ylim(0,200) +
  geom_smooth(aes(x=Reported,y=Deaths,col="Loess"),span=0.25) +
   scale_alpha_date()
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
## Warning: Removed 44 rows containing non-finite values (stat_smooth).
## Warning: Removed 1 rows containing missing values (geom_smooth).

Non-Moving Average By Week and By Month

US$Monthly <- as.Date(cut(US$Reported,
  breaks = "month"))
US$Weekly <- as.Date(cut(US$Reported,
  breaks = "week",
  start.on.monday = FALSE))
Weekly_Cases <- aggregate(Cases~Weekly,US,FUN=sum)
Weekly_Deaths <- aggregate(Deaths~Weekly,US,FUN=sum)
Weekly_Cases$DRate <- Weekly_Deaths$Deaths/Weekly_Cases$Cases
Weekly_Cases$LivedSaved <- Weekly_Cases$Cases * (max(Weekly_Cases$DRate) - Weekly_Cases$DRate) 
ggplot(Weekly_Cases) + geom_col(aes(x=Weekly,y=Cases)) + 
  labs(title="Weekly Cases",x="Date Reported", y="Weekly Cases") +
   scale_alpha_date()

ggplot(Weekly_Deaths) + geom_col(aes(x=Weekly,y=Deaths)) + 
  labs(title="Weekly Deaths",x="Date Reported", y="Weekly Deaths") +
   ylim(0,6000) +  scale_alpha_date()

Monthly Cases and Deaths

Monthly_Cases <- aggregate(Cases~Monthly,US,FUN=sum)
Monthly_Deaths <- aggregate(Deaths~Monthly,US,FUN=sum)
Monthly_Cases$DRate <- Monthly_Deaths$Deaths/Monthly_Cases$Cases
Monthly_Cases$LivedSaved <- Monthly_Cases$Cases * (max(Monthly_Cases$DRate) - Monthly_Cases$DRate) * 100
ggplot(Monthly_Cases) + geom_col(aes(x=Monthly,y=Cases)) +
  labs(title="Monthly Cases") +
  scale_y_continuous(labels=scales::comma) +
   scale_alpha_date()

ggplot(Monthly_Deaths) + geom_col(aes(x=Monthly,y=Deaths)) +
  labs(title="Monthly Deaths") +
   scale_alpha_date()